<?php

namespace App\Http\Controllers\Labaicai;

use App\Http\Requests\Labaicai\FooodCategoriesRequest;
use App\Http\Resources\Labaicai\FooodCategoriesResource;
use App\Models\Labaicai\FooodCategories;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class FooodCategoriesController extends Controller
{
    public function __construct()
    {
    }

    /**
     * Notes:
     * Created on 2024-02-18 01:08:51
     * @param Request $request
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
     */
    public function index(Request $request)
    {
        $query = FooodCategories::with('foods')->filter();
        return FooodCategoriesResource::collection(
            $request->has('page') ? $query->paginate(per()) : $query->get()
        );
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(FooodCategoriesRequest $request)
    {
        FooodCategories::create($request->all());
    }

    /**
     * Notes:
     * Created on 2024-02-18 01:08:51
     * @param $id
     * @return FooodCategoriesResource
     */
    public function show($id)
    {
        return FooodCategoriesResource::make(FooodCategories::findOrFail($id));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function update(FooodCategoriesRequest $request, $id)
    {
        FooodCategories::where('id', $id)->updateFillable($request->all());
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $m = FooodCategories::findOrFail($id);
        $m->delete();
    }
}
